<template>
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="是否匿名" prop="isAnonymity">
        <el-select
          v-model="queryParams.isAnonymity"
          placeholder="请选择"
          clearable
          class="!w-240px"
        >
          <el-option
            v-for="dict in getIntDictOptions(DICT_TYPE.IS_ANONYMITY)"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <!-- <el-form-item label="举报类别" prop="category">
        <el-select
          v-model="queryParams.category"
          placeholder="请选择"
          clearable
          class="!w-240px"
        >
          <el-option
            v-for="dict in getStrDictOptions(DICT_TYPE.CATEGORY)"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item> -->
      <!-- <el-form-item label="举报类别详情" prop="categoryDetail">
        <el-input
          v-model="queryParams.categoryDetail"
          placeholder="请输入举报类别详情"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item> -->
      <el-form-item label="受理情况" prop="acceptSituation">
        <el-select
          v-model="queryParams.acceptSituation"
          placeholder="请选择"
          clearable
          class="!w-240px"
        >
          <el-option
            v-for="dict in getStrDictOptions(DICT_TYPE.ACCEPT_SITUATION)"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="线索情况" prop="clueSituation">
        <el-select
          v-model="queryParams.clueSituation"
          placeholder="请选择"
          clearable
          class="!w-240px"
        >
          <el-option
            v-for="dict in getStrDictOptions(DICT_TYPE.CLUE_SITUATION)"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>







      <el-form-item>
        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
        <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
        <!-- <el-button
          type="primary"
          plain
          @click="openForm('create')"
          v-hasPermi="['system:reporting:create']"
        >
          <Icon icon="ep:plus" class="mr-5px" /> 新增
        </el-button> -->
        <!-- <el-button
          type="success"
          plain
          @click="handleExport"
          :loading="exportLoading"
          v-hasPermi="['system:reporting:export']"
        >
          <Icon icon="ep:download" class="mr-5px" /> 导出
        </el-button> -->
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
          <!-- 序号 -->
      <el-table-column prop="scope" type="index" :show-overflow-tooltip="true" width="100" label="序号" align="center">
						<template #default="scope">
							<span>{{scope.$index +  queryParams.pageSize * (queryParams.pageNo - 1) + 1}}</span>
						</template>
			</el-table-column>

      <!-- <el-table-column label="ID" align="center" prop="id" /> -->
      <el-table-column label="是否匿名" align="center" prop="isAnonymity">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.IS_ANONYMITY" :value="scope.row.isAnonymity" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="举报人id" align="center" prop="userId" />
      <el-table-column label="举报人姓名" align="center" prop="reportName" />
      <el-table-column label="举报人身份证号" align="center" prop="reportIdentityCard" />
      <el-table-column label="举报人居住地" align="center" prop="reportAddress" />
      <el-table-column label="举报人联系方式" align="center" prop="reportTel" />
      <el-table-column label="被举报人姓名" align="center" prop="beReportedName" />
      <el-table-column label="被举报人单位" align="center" prop="beReportedUnit" />
      <el-table-column label="被举报人职务" align="center" prop="beReportedOffice" />
      <el-table-column label="被举报人级别" align="center" prop="beReportedLevel" /> -->
      <el-table-column label="标题" align="center" prop="title" />
      <!-- <el-table-column label="举报类别" align="center" prop="category">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.CATEGORY" :value="scope.row.category" />
        </template>
      </el-table-column>
      <el-table-column label="举报类别详情" align="center" prop="categoryDetail">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.CATEGORY_DETAIL" :value="scope.row.categoryDetail" />
        </template>
      </el-table-column>
      <el-table-column label="详细内容" align="center" prop="content" />
      <el-table-column label="文件id" align="center" prop="fileId" /> -->
      <el-table-column label="受理情况" align="center" prop="acceptSituation">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.ACCEPT_SITUATION" :value="scope.row.acceptSituation" />
        </template>
      </el-table-column>
      <el-table-column label="线索情况" align="center" prop="clueSituation">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.CLUE_SITUATION" :value="scope.row.clueSituation" />
        </template>
      </el-table-column>
      <!-- <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        :formatter="dateFormatter"
        width="180px"
      />
      <el-table-column label="受理情况说明" align="center" prop="illustrate" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="创建者" align="center" prop="creator" />
      <el-table-column label="是否查看" align="center" prop="isSee" /> -->

      <el-table-column label="操作" align="center" min-width="120px">
        <template #default="scope">
          <el-button
            link
            type="primary"
            @click="openForm('update', scope.row.id)"
            v-hasPermi="['system:reporting:update']"
          >
            编辑
          </el-button>
          <!-- <el-button
            link
            type="danger"
            @click="handleDelete(scope.row.id)"
            v-hasPermi="['system:reporting:delete']"
          >
            删除
          </el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>

  <!-- 表单弹窗：添加/修改 -->
  <ReportingForm ref="formRef" @success="getList" />
</template>

<script setup lang="ts">
import { getIntDictOptions, getStrDictOptions, DICT_TYPE } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download'
import { ReportingApi, ReportingVO } from '@/api/system/reporting'
import ReportingForm from './ReportingForm.vue'

/** 投诉信息 列表 */
defineOptions({ name: 'Reporting' })

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const loading = ref(true) // 列表的加载中
const list = ref<ReportingVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  isAnonymity: undefined,
  userId: undefined,
  reportName: undefined,
  reportIdentityCard: undefined,
  reportAddress: undefined,
  reportTel: undefined,
  beReportedName: undefined,
  beReportedUnit: undefined,
  beReportedOffice: undefined,
  beReportedLevel: undefined,
  title: undefined,
  category: '1',
  categoryDetail: undefined,
  content: undefined,
  fileId: undefined,
  acceptSituation: undefined,
  clueSituation: undefined,
  createTime: [],
  illustrate: undefined,
  remark: undefined,
  creator: undefined,
  isSee: undefined,
  state: undefined,
  stateOne: undefined,
  stateTwo: undefined,
  staeThree: undefined,
  stateFour: undefined,
  stateFive: undefined,
})
const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) // 导出的加载中

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await ReportingApi.getReportingPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}

/** 添加/修改操作 */
const formRef = ref()
const openForm = (type: string, id?: number) => {
  formRef.value.open(type, id)
}

/** 删除按钮操作 */
const handleDelete = async (id: number) => {
  try {
    // 删除的二次确认
    await message.delConfirm()
    // 发起删除
    await ReportingApi.deleteReporting(id)
    message.success(t('common.delSuccess'))
    // 刷新列表
    await getList()
  } catch {}
}

/** 导出按钮操作 */
const handleExport = async () => {
  try {
    // 导出的二次确认
    await message.exportConfirm()
    // 发起导出
    exportLoading.value = true
    const data = await ReportingApi.exportReporting(queryParams)
    download.excel(data, '投诉信息.xls')
  } catch {
  } finally {
    exportLoading.value = false
  }
}

/** 初始化 **/
onMounted(() => {
  getList()
})
</script>